﻿Option Explicit On

Namespace CheckINI

    Module modCheck

        Private Function JSTrim(ByVal str As String) As ArrayList

            Dim tmpArray As New ArrayList

            If str.IndexOf(";") <> -1 Then
                str = str.Substring(0, str.IndexOf(";"))
            End If

            If str.IndexOf("[") <> -1 Then
                Dim str1 As Boolean = True
                Dim str2 As String = str.Substring(str.IndexOf("[") + 1, str.IndexOf("]"))
                tmpArray.Add(str1)
                tmpArray.Add(str2)
            ElseIf str.IndexOf("=") <> -1 Then
                Dim str1 As String = trimSpace(str.Substring(0, str.IndexOf("=")))
                Dim str2 As String = trimSpace(str.Substring(str.IndexOf("=") + 1))
                tmpArray.Add(str1)
                tmpArray.Add(str2)
            Else
                Dim str1 As Boolean = False
                Dim str2 As String = Nothing
                tmpArray.Add(str1)
                tmpArray.Add(str2)
            End If

            Return tmpArray

        End Function

        Private Function trimSpace(ByVal strx As String) As String

            If strx <> "" Then
                While strx.Substring(0, 1) = "" Or strx.Substring(0, 1) = "	"
                    strx = strx.Substring(1)
                End While

                While strx.Substring(strx.Length - 1) = " " Or strx.Substring(strx.Length - 1) = "	"
                    strx = strx.Substring(0, strx.Length - 1)
                End While
                Return strx
            End If

        End Function

        Private Function IsWeapon(ByVal it As String) As Boolean

            If it = "Primary" Or it = "Secondary" Or it = "ElitePrimary" Or it = "EliteSecondary" Or it = "DeathWeapon" Or (it.Substring(0, 6) = "Weapon" And Single.IsNaN(it.Substring(6))) = True Or (it.Substring(0, 11) = "EliteWeapon" And Single.IsNaN(it.Substring(11)) = True) Then
                Return True
            Else
                Return False
            End If

        End Function

        Public Function JSCheckWeapons(ByVal Array As KeyValue.INISection()) As String
            Dim INIContext As String = ""
            Dim Output As String = ""

            For Each unitSec In Array
                If INIContext = "" Then
                    INIContext = INIContext + unitSec.SectionContext
                Else
                    If unitSec.SectionName = "AudioVisual" Then
                        INIContext = INIContext + vbCrLf + unitSec.SectionContext
                    End If
                End If
            Next
            Dim INIContextLine As String() = ConvertStringToLines(INIContext)

            Dim registeredWeapons As New ArrayList
            Dim loadedWeapons As New ArrayList
            Dim obj1 As New ArrayList
            Dim currentSection As String = "none"

            Do
                Dim a As New ArrayList
                Dim s As String
                a = JSTrim(s)
                If a(0) = True Then
                    currentSection = a(1)
                    obj1.Add(New ArrayList)
                ElseIf a(0) <> False Then

                End If

            Loop

        End Function

    End Module

End Namespace
